Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Collaboration: Replace Poxa with Action Cable #3105

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sammo1235
Copy link
Contributor

@sammo1235 sammo1235 commented Oct 11, 2024

📝 A short description of the changes

  • Includes behaviour:
  • Two users cannot edit the same form at the same time
  • If one user moves on to a new section (step) of the form, then then previous section is released for editing for the next user in the queue
  • blocks a user from editing when they have two tabs of the same form opened.

🔗 Link to the relevant story (or stories)

:shipit: Deployment implications

  • Remove Pusher ENV vars and setup code.
  • Allow action cable to talk to Redis (setup should be straightforward)

✅ Checklist

  • Features that cannot go live are behind a feature flag/env var or specify deploy date and open PR as draft
  • I have checked that commit messages make sense and explain the reasoning for each change
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have squashed any unnecessary or part-finished commits

🖼️ Screenshots (if appropriate - no PII/Prod data):

  1. If you have two users logged in at once, the second one to see the form section will see this message and not be able to edit the form:
    Screenshot 2024-12-11 at 11 02 11

If the first user moves away from that form section, closes their tab etc, then editing should be released to the second user.

  1. Same user opening a second tab of the same form section:
    Screenshot 2024-12-11 at 11 04 19

This should have a similar effect but with a slightly different warning message. The user can close either tab, and the remaining one will be able to edit.

@@ -842,7 +842,7 @@ window.FormValidation =
qRef = question.attr("data-question_ref")
qTitle = $.trim(question.find("h2").first().text())

if typeof console != "undefined"
if typeof console != "undefined" && false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[TODO] remove once testing is complete - this output will muddy the waters

@sammo1235 sammo1235 force-pushed the replace-poxa-with-action-cable-spike branch 6 times, most recently from 21b863b to e021984 Compare December 10, 2024 17:03
@sammo1235 sammo1235 changed the title [SPIKE] Replace Poxa with Action Cable Form Collaboration: Replace Poxa with Action Cable Dec 11, 2024
get_member_info: (m) ->
return ("ID: " + m.id + ", NAME: " + m.info.name + ", JOINED AT: " + m.info.joined_at)
current_editor_id: () ->
editor_id = window.current_channel_members.split("/").find((el) => el.includes("EDITOR")).split(":")[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just reuse current_editor() here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I've updated

collaborators += "/#{user.id}:#{params["current_tab"]}:#{user.email}:#{user.full_name}"
end

Rails.cache.write(params["channel_name"], collaborators)
Copy link
Contributor

@phil-l-brockwell phil-l-brockwell Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just keep collaborators as an array as it should be automatically serialised? Or do we need to do it this way so we know how to unserialise it in the JS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the JS does rely on the members being separated by a slash

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if you pass in an array it must serialise it in its own way. might be neater if we depend on that instead

@@ -93,6 +94,10 @@ def should_enable_js?
helper_method "#{award}_submission_started_deadline"
end

def set_session_identifier
cookies["public_tab_ident"] = cookies["_qae_session#{"_development" if Rails.env.development?}"]&.first(8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the first(8)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just gets the first 8 characters, as a way of telling the tabs apart for one user

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah so its an identifier for the tab, which is always 8 chars long?

…ng forms behaviour

Implements two main behaviours using ActionCable:
1. If a second user has the same section of a form open, they cannot edit it. However if the first user closes their tab
or moves on to a different section then editing rights are released to the second user.
2. If user 1 opens a second tab of the same form, they cannot edit in the second tab. They are shown a message telling them
to close the tab and edit in the first tab.
@sammo1235 sammo1235 force-pushed the replace-poxa-with-action-cable-spike branch from f87be1a to 0adafca Compare December 11, 2024 15:41
@sammo1235 sammo1235 marked this pull request as ready for review December 11, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants